package org.petstore.web.servlet;


import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

import static org.petstore.web.servlet.util.ServletUtil.MAIN_FORM;

public class MainServlet extends HttpServlet  {



    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) {
        try {
            doGet(req, resp);
        } catch (ServletException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
//        String username = req.getParameter("username");
//        String password = req.getParameter("password");
//
//        try {
//            //为空判断
//            if (username.isEmpty()) {
//                req.setAttribute("loginMsg", "用户名不能为空");
//                req.getRequestDispatcher("login.jsp").forward(req, resp);
//            } else if (password.isEmpty()) {
//                req.setAttribute("loginMsg", "密码不能为空");
//                req.getRequestDispatcher(LOGIN_FORM).forward(req, resp);
//            }
//
//            //todo 位数判断 大小写判断
//
//            //获取 loginUser
//            User loginUser = userService.Login(username, password);
//            if (loginUser == null) {
//                req.setAttribute("loginMsg", "用户名或密码错误");
//                req.getRequestDispatcher(LOGIN_FORM).forward(req, resp);
//            } else {
//                HttpSession session = req.getSession();
//                session.setAttribute("loginUser", loginUser);
//            }
//
//        } catch (ServletException | IOException e) {
//            e.printStackTrace();
//        }
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        req.getRequestDispatcher(MAIN_FORM).forward(req, resp);
    }
    //todo  req resp的操作(页面跳转 session等)
}

